z = int(input())
s = set()
if len(str(z)) <= 3 or len(str(z)) > 4:
    print(0)
    exit()
for i in range(0, 4):
    if str(z)[i] == '3':
        s.add(3)
    elif str(z)[i] == '5':
        s.add(5)
    elif str(z)[i] == '7':
        s.add(7)
    elif str(z)[i] == '2':
        s.add(2)
xos = 0
sox = 0
for q in range(0, 3):
    sox = int(str(z)[q] + str(z)[q + 1])
    for x in range(2, sox - 1):
        if sox % x == 0:
            xos += 1
            break
    if xos == 0:
        s.add(sox)
    xos = 0
xos = 0
sox = 0
for q in range(0, 2):
    sox = int(str(z)[q] + str(z)[q + 1] + str(z)[q + 2])
    for x in range(2, sox - 1):
        if sox % x == 0:
            xos += 1
            break
    if xos == 0:
        s.add(sox)
    xos = 0
for x in range(2, z):
    if z % x == 0:
        xos += 1
        break
if xos == 0:
    s.add(z)
if len(s) == 0:
    print('0')
else:
    print(max(s))

